package com.xqb.modules.controller.media;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.MedBanner;
import com.xqb.modules.service.IMedBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 轮播图Controller
 *
 * @author xqb
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/media/banner")
public class MedBannerController extends BaseController {
    @Autowired
    private IMedBannerService medBannerService;

    /**
     * 查询轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('media:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedBanner medBanner) {
        startPage();
        List<MedBanner> list = medBannerService.selectMedBannerList(medBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('media:banner:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedBanner medBanner) {
        List<MedBanner> list = medBannerService.selectMedBannerList(medBanner);
        ExcelUtil<MedBanner> util = new ExcelUtil<MedBanner>(MedBanner.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('media:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(medBannerService.selectMedBannerById(id));
    }

    /**
     * 新增轮播图
     */
    @PreAuthorize("@ss.hasPermi('media:banner:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedBanner medBanner) {
        return toAjax(medBannerService.insertMedBanner(medBanner));
    }

    /**
     * 修改轮播图
     */
    @PreAuthorize("@ss.hasPermi('media:banner:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedBanner medBanner) {
        return toAjax(medBannerService.updateMedBanner(medBanner));
    }

    /**
     * 删除轮播图
     */
    @PreAuthorize("@ss.hasPermi('media:banner:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(medBannerService.deleteMedBannerByIds(ids));
    }
}
